package com.evolution.warlock.controller.admin;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.evolution.warlock.entity.Admin;
import com.evolution.warlock.entity.CriminalBase;
import com.evolution.warlock.entity.RobSteal;
import com.evolution.warlock.entity.MasterConfig.KeyType;
import com.evolution.warlock.service.AdminService;
import com.evolution.warlock.service.CriminalBaseService;
import com.evolution.warlock.service.MasterConfigService;
import com.evolution.warlock.service.RobStealService;

@Controller("robStealController")
@RequestMapping("/admin/robsteal")
public class RobStealController extends BaseController {
	
	@Resource(name = "masterConfigServiceImpl")
	private MasterConfigService masterConfigService;
	@Resource(name = "robStealServiceImpl")
	private RobStealService robStealService;
	@Resource(name = "adminServiceImpl")
	private AdminService adminService;
	@Resource(name = "criminalBaseServiceImpl")
	private CriminalBaseService criminalBaseService;	
	
	/**
	 * 增加
	 */
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(String criminalNumber, ModelMap model) {
		
		model.addAttribute("criminalNumber", criminalNumber);
		
		Admin admin = adminService.getCurrent();
		model.addAttribute("departmentName", admin.getDepartment());
		model.addAttribute("policerName", admin.getName());
		
		model.addAttribute("commonHave", masterConfigService.findList(KeyType.COMMON_HAVE.getValue()));
		model.addAttribute("commonBool", masterConfigService.findList(KeyType.COMMON_BOOLEAN.getValue()));
		
		model.addAttribute("genderGroup", masterConfigService.findList(KeyType.GENDER.getValue()));
	    model.addAttribute("criminalAreaChoiceGroup", masterConfigService.findList(KeyType.CRIMINAL_AREA_CHOICE.getValue()));
	   
	    model.addAttribute("robberySnatchCategoryGroup", masterConfigService.findList(KeyType.ROBBERY_SNATCH_CATEGORY.getValue()));
	    model.addAttribute("theftCategoryGroup", masterConfigService.findList(KeyType.THEFT_CATEGORY.getValue()));
	    model.addAttribute("sharpCategoryGroup", masterConfigService.findList(KeyType.SHARP_CATEGORY.getValue()));

	    model.addAttribute("criminalMainReasonGroup", masterConfigService.findList(KeyType.CRIMINAL_MAIN_REASON.getValue()));
	    model.addAttribute("localCriminalReasonGroup", masterConfigService.findList(KeyType.LOCAL_CRIMINAL_REASON.getValue()));
	    
	    model.addAttribute("frequentedAccessHotelLevelGroup", masterConfigService.findList(KeyType.FRE_ACESS_HOTEL_LEVL.getValue()));
	    model.addAttribute("addressAfterCrimeCategoryGroup", masterConfigService.findList(KeyType.ADDR_AFT_CRIME.getValue()));
	    
	    model.addAttribute("favoriteAmusementOptionGroup", masterConfigService.findList(KeyType.FAV_AMUSE_OPT.getValue()));
	    model.addAttribute("transportationToolsGroup", masterConfigService.findList(KeyType.CRIMI_TANS_TOOL.getValue()));
	    model.addAttribute("transportationToolSourceGroup", masterConfigService.findList(KeyType.CRIMI_TANS_TOOL_SOUR.getValue()));
	    
	    model.addAttribute("bootySellPositionGroup", masterConfigService.findList(KeyType.BOOT_SELL_POS.getValue()));
	    model.addAttribute("bootySellCategoryGroup", masterConfigService.findList(KeyType.BOOT_SELL_CATE.getValue()));
	    
	    model.addAttribute("illegalMoneyGroup", masterConfigService.findList(KeyType.ILLEGAL_MONEY.getValue()));
	    
	    model.addAttribute("censusOptionGroup", masterConfigService.findList(KeyType.CENSUS_OPTION.getValue()));
	    model.addAttribute("trafficOptionGroup", masterConfigService.findList(KeyType.TRAFFIC_OPTION.getValue()));
	    model.addAttribute("reportOptionGroup", masterConfigService.findList(KeyType.REPORT_OPTION.getValue()));
	    
	    return "/admin/robsteal/add";
	}

	/**
	 * 保存
	 */
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public String save(RobSteal robSteal, RedirectAttributes redirectAttributes) {
		
		Admin admin = adminService.getCurrent();

		robStealService.save(robSteal);
		addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
		return "redirect:/admin/criminalbase/list.jhtml";
	}
	
	
	/**
	 * 查看
	 */
	@RequestMapping(value = "/view", method = RequestMethod.GET)
	public String view(String criminalNumber, ModelMap model) {
		
		RobSteal robSteal = robStealService.findRobSteal(Long.valueOf(criminalNumber));
		model.addAttribute("robSteal", robSteal);
		
		model.addAttribute("commonHave", masterConfigService.findList(KeyType.COMMON_HAVE.getValue()));
		model.addAttribute("commonBool", masterConfigService.findList(KeyType.COMMON_BOOLEAN.getValue()));
		
		model.addAttribute("genderGroup", masterConfigService.findList(KeyType.GENDER.getValue()));
	    model.addAttribute("criminalAreaChoiceGroup", masterConfigService.findList(KeyType.CRIMINAL_AREA_CHOICE.getValue()));
	   
	    model.addAttribute("robberySnatchCategoryGroup", masterConfigService.findList(KeyType.ROBBERY_SNATCH_CATEGORY.getValue()));
	    model.addAttribute("theftCategoryGroup", masterConfigService.findList(KeyType.THEFT_CATEGORY.getValue()));
	    model.addAttribute("sharpCategoryGroup", masterConfigService.findList(KeyType.SHARP_CATEGORY.getValue()));

	    model.addAttribute("criminalMainReasonGroup", masterConfigService.findList(KeyType.CRIMINAL_MAIN_REASON.getValue()));
	    model.addAttribute("localCriminalReasonGroup", masterConfigService.findList(KeyType.LOCAL_CRIMINAL_REASON.getValue()));
	    
	    model.addAttribute("frequentedAccessHotelLevelGroup", masterConfigService.findList(KeyType.FRE_ACESS_HOTEL_LEVL.getValue()));
	    model.addAttribute("addressAfterCrimeCategoryGroup", masterConfigService.findList(KeyType.ADDR_AFT_CRIME.getValue()));
	    
	    model.addAttribute("favoriteAmusementOptionGroup", masterConfigService.findList(KeyType.FAV_AMUSE_OPT.getValue()));
	    model.addAttribute("transportationToolsGroup", masterConfigService.findList(KeyType.CRIMI_TANS_TOOL.getValue()));
	    model.addAttribute("transportationToolSourceGroup", masterConfigService.findList(KeyType.CRIMI_TANS_TOOL_SOUR.getValue()));
	    
	    model.addAttribute("bootySellPositionGroup", masterConfigService.findList(KeyType.BOOT_SELL_POS.getValue()));
	    model.addAttribute("bootySellCategoryGroup", masterConfigService.findList(KeyType.BOOT_SELL_CATE.getValue()));
	    
	    model.addAttribute("illegalMoneyGroup", masterConfigService.findList(KeyType.ILLEGAL_MONEY.getValue()));
	    
	    model.addAttribute("censusOptionGroup", masterConfigService.findList(KeyType.CENSUS_OPTION.getValue()));
	    model.addAttribute("trafficOptionGroup", masterConfigService.findList(KeyType.TRAFFIC_OPTION.getValue()));
	    model.addAttribute("reportOptionGroup", masterConfigService.findList(KeyType.REPORT_OPTION.getValue()));

		return "/admin/robsteal/view";
	}
	
	/**
	 * 修改
	 */
	@RequestMapping(value = "/edit", method = RequestMethod.GET)
	public String edit(String criminalNumber, ModelMap model){
		
		RobSteal robSteal = robStealService.findRobSteal(Long.valueOf(criminalNumber));
		model.addAttribute("robSteal", robSteal);		
	
		model.addAttribute("commonHave", masterConfigService.findList(KeyType.COMMON_HAVE.getValue()));
		model.addAttribute("commonBool", masterConfigService.findList(KeyType.COMMON_BOOLEAN.getValue()));
		
		model.addAttribute("genderGroup", masterConfigService.findList(KeyType.GENDER.getValue()));
	    model.addAttribute("criminalAreaChoiceGroup", masterConfigService.findList(KeyType.CRIMINAL_AREA_CHOICE.getValue()));
	   
	    model.addAttribute("robberySnatchCategoryGroup", masterConfigService.findList(KeyType.ROBBERY_SNATCH_CATEGORY.getValue()));
	    model.addAttribute("theftCategoryGroup", masterConfigService.findList(KeyType.THEFT_CATEGORY.getValue()));
	    model.addAttribute("sharpCategoryGroup", masterConfigService.findList(KeyType.SHARP_CATEGORY.getValue()));

	    model.addAttribute("criminalMainReasonGroup", masterConfigService.findList(KeyType.CRIMINAL_MAIN_REASON.getValue()));
	    model.addAttribute("localCriminalReasonGroup", masterConfigService.findList(KeyType.LOCAL_CRIMINAL_REASON.getValue()));
	    
	    model.addAttribute("frequentedAccessHotelLevelGroup", masterConfigService.findList(KeyType.FRE_ACESS_HOTEL_LEVL.getValue()));
	    model.addAttribute("addressAfterCrimeCategoryGroup", masterConfigService.findList(KeyType.ADDR_AFT_CRIME.getValue()));
	    
	    model.addAttribute("favoriteAmusementOptionGroup", masterConfigService.findList(KeyType.FAV_AMUSE_OPT.getValue()));
	    model.addAttribute("transportationToolsGroup", masterConfigService.findList(KeyType.CRIMI_TANS_TOOL.getValue()));
	    model.addAttribute("transportationToolSourceGroup", masterConfigService.findList(KeyType.CRIMI_TANS_TOOL_SOUR.getValue()));
	    
	    model.addAttribute("bootySellPositionGroup", masterConfigService.findList(KeyType.BOOT_SELL_POS.getValue()));
	    model.addAttribute("bootySellCategoryGroup", masterConfigService.findList(KeyType.BOOT_SELL_CATE.getValue()));
	    
	    model.addAttribute("illegalMoneyGroup", masterConfigService.findList(KeyType.ILLEGAL_MONEY.getValue()));
	    
	    model.addAttribute("censusOptionGroup", masterConfigService.findList(KeyType.CENSUS_OPTION.getValue()));
	    model.addAttribute("trafficOptionGroup", masterConfigService.findList(KeyType.TRAFFIC_OPTION.getValue()));
	    model.addAttribute("reportOptionGroup", masterConfigService.findList(KeyType.REPORT_OPTION.getValue()));

		return "/admin/robsteal/edit";
	}
	
	/**
	 * 修改
	 */
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public String update(RobSteal robSteal, RedirectAttributes redirectAttributes) {
		
		Admin admin = adminService.getCurrent();
		
		robStealService.update(robSteal);
		addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
		return "redirect:/admin/criminalbase/list.jhtml";
	}
	
}
